package com.example.webservice.server.config;

import com.example.webservice.server.service.HelloService;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @Author hweiyu
 * @Description
 * @Date 2021/4/21 17:55
 */
@Configuration
public class WebServiceConfig {

    /**
     * Bus交由spring管理
     * @return
     */
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    /**
     * 服务地址：
     * http://localhost:8080/services
     * http://localhost:8080/services/v1/demo?wsdl
     * @param helloService
     * @return
     */
    @Bean
    public Endpoint endpoint(HelloService helloService) {
        EndpointImpl endpoint = new EndpointImpl(springBus(), helloService);
        endpoint.publish("/v1/demo");
        return endpoint;
    }
}
